package com.smartum.mpr.dao;

import java.io.Serializable;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;

public abstract class GenericDao<PK extends Serializable, T> extends BaseDao<T> {

	public T get(PK id) {
		LOG.info(String.format("get %s by id: %s ", getEntityClass(), id));
		return hibernateTemplate.get(getEntityClass(), id);
	}

	public List<T> getList() {
		LOG.info(String.format("list %s ", getEntityClass()));
		return hibernateTemplate.findByCriteria(DetachedCriteria.forClass(getEntityClass()));
	}

	public void delete(PK id) {
		LOG.info(String.format("delete %s by id: %s ", getEntityClass(), id));
		hibernateTemplate.delete(get(id));
	}

	protected abstract Class<T> getEntityClass();
}
